﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FAP.Cores.CaptchaCenter;
using FAP.Cores.Threading;
using System.Net;
using FAP.RegisterTask;
using FAP.Login;
using FAP.DataAccess;
using FAP.Cores.Task;
using WebLibs;
using FAP.DataAccess.BLL;

namespace FAP.FormTestCores
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            FAP.Cores.CaptchaCenter.CaptchaManager.StartServer();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            CaptchaDTO c = new CaptchaDTO();
            c.xpath = "/html/body/div[3]/form/div/div/div[4]/div/p" + "%" + "//*[@id=\"registerform\"]/div[1]/div[1]/div[4]/div/p";
            Cores.Requesting.Requester rq = new Cores.Requesting.Requester();
            string url = "http://ddcntt.vn/forum/register.php";
            c.html = rq.GetHtmlFromResponse(rq.GetData(url));
            c.fieldNameVerifyCaptcha = "humanverify[hash]";
            
            var t = new CaptchaTask(c);
            t.onFinished += onFinished;
            t.onError += onError;
            FAP.Cores.Threading.ThreadControl.AddTasks(t);
        }

        public static void onFinished(object sender, object result)
        {
            if (result == null)
                return;
            CaptchaDTO c = (CaptchaDTO)result;
            MessageBox.Show(c.captcha + "-" + c.valueVerifyCatcha);

        }

        public static void onError(object sender, object result)
        {
            //m_log.Error(result);
            MessageBox.Show("onError");
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            chitietnghiepvu ctnv = chitietnghiepvu.chitietnghiepvuSelectRow(592);

            taikhoan tk =  taikhoan.taikhoanSelectRow(2);
            LoginTask fw = new LoginTask(ctnv,"0");
            fw.m_tk = tk;
            fw.onFinished += onFinishedPoster;
            fw.onError += onErrorPoster;
            fw.TaskName = "TestTask";
            //fw.RunIt();
            FAP.Cores.Threading.ThreadControl.AddTasks(fw);
        }
        public static void onFinishedPoster(object sender, object result)
        {
            MessageBox.Show("onFinishedPoster");
        }

        public static void onErrorPoster(object sender, object result)
        {
            //m_log.Error(result);
            Exception e = (Exception)result;
            MessageBox.Show(e.StackTrace);
        }

        private void button3_Click(object sender, EventArgs e)
        {
        }

    }
}
